home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / comm / avm / rexx / silentanswer.avm < prev    next >
Encoding:
Text File  |  1994-04-06  |  11.4 KB  |  468 lines

  1. /* TITLE: avm:source/silentanswer.avmsrc */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername faxscript datascript distinctivering 'CID$' acidname '$' acidnumber '$'
  23.  
  24. /* Initialize log entry */
  25.  
  26. handle = makeUniqueFile()
  27. call initLogEntry()
  28. log.type = '?'
  29. mailbox = 'silent'
  30.  
  31. /* Put beep in here if you want */
  32.  
  33. readkeyagain:
  34. 'readnkeys' '1' '90'
  35. action = rc
  36. if action = 0 then value = result
  37. select
  38.   when action = 0 then signal possiblechoice
  39.   when action = 4 then signal stdfax
  40.   when action = 5 then signal stddata
  41.   when action = 8 then nop
  42.   when action = 10 then nop
  43.   when action = 12 then signal stdabort
  44.   when action = 14 then signal stderror
  45.   when action = 16 then signal stderror
  46.   otherwise signal arexxerror
  47. end
  48.  
  49. /* Put another beep in here if you want */
  50.  
  51. finished:
  52. /* Save log entry */
  53.  
  54. log.filename = handle
  55. log.comment = 'Silent Answer'
  56. call saveLogEntry(mailbox, handle)
  57. exit
  58.  
  59. possiblechoice:
  60. select
  61.   when value = '2' then signal stdfax
  62.   when value = '1' then signal dorecord
  63.   when value = '5' then signal stddata
  64.   when value = '*' then signal stdabort
  65.   otherwise nop
  66. end
  67. signal finished
  68.  
  69. dorecord:
  70. call time('r')
  71.  
  72. 'recordvoice' '120' '-1' '-1' handle
  73. action = rc
  74. select
  75.   when action = 0 then nop
  76.   when action = 1 then nop
  77.   when action = 2 then nop
  78.   when action = 3 then nop
  79.   when action = 4 then signal stdfax
  80.   when action = 5 then signal stddata
  81.   when action = 8 then nop
  82.   when action = 10 then nop
  83.   when action = 12 then signal stdabort
  84.   when action = 14 then signal stderror
  85.   when action = 16 then signal stderror
  86.   otherwise signal arexxerror
  87. end
  88.  
  89. log.type = 'voice'
  90. log.length = trunc(time('e'))
  91. signal finished
  92.  
  93. /* TITLE: avm:source/simplestdtail.avmsrc */
  94. /* This is the standard tail */
  95. exit
  96.  
  97. exit
  98.  
  99. mailboxDir: procedure
  100.     parse arg mailbox
  101.  
  102.     return 'avm:' || mailbox || '/'
  103.  
  104. logFile: procedure
  105.     parse arg mailbox, magiccookie
  106.  
  107.     return 'avm:' || mailbox || '/logs/' || magiccookie
  108.  
  109. voiceFile: procedure
  110.     parse arg mailbox, magiccookie
  111.  
  112.         if (verify(magiccookie, '/:', 'M') = 0) then
  113.           return 'avm:' || mailbox || '/voices/' || magiccookie
  114.         else
  115.           return magiccookie
  116.  
  117. makeUniqueFile: procedure
  118.     if arg() ~= 0 then do
  119.         rc = "makeUniqueFile: bad args"
  120.         signal error
  121.     end
  122.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  123.  
  124. convertToDate: procedure
  125.     if arg() ~= 1 then do
  126.         rc = "convertToDate: bad args"
  127.         signal error
  128.     end
  129.     parse arg timeInC
  130.  
  131.     actualTime = (timeInC - (2922)*86400) // (86400)
  132.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  133.  
  134.     return actualDate /* returning it in 'internal' format */
  135.  
  136. convertToTime: procedure
  137.     if arg() ~= 1 then do
  138.         rc = "convertToTime: bad args"
  139.         signal error
  140.     end
  141.     parse arg timeInC
  142.     
  143.     actualTime = (timeInC - (2922)*86400) // (86400)
  144.  
  145.     return actualTime
  146.  
  147. cTime: procedure
  148.     /* 2922 = 8*365 + 2 */
  149.     /* 86400 = 24*60*60 */
  150.     return (date('i')+2922)*86400 + time('s')
  151.  
  152. /* this returns a handle that you must use after initializing log. */
  153. initLogEntry: procedure expose log.
  154.     if arg() ~= 0 then do
  155.         rc = "initLogEntry: bad args"
  156.         signal error
  157.     end
  158.     
  159.     drop log.
  160.         log. = ''
  161.  
  162.         acidname = getclip(address() || 'CIDNAME')
  163.         acidnumber = getclip(address() || 'CIDNUMBER')
  164.  
  165.     /* 2922 = 8*365 + 2 */
  166.     /* 86400 = 24*60*60 */
  167.     log.time = (date('i')+2922)*86400 + time('s')
  168.     log.cidname = acidname
  169.     log.cidnumber = acidnumber
  170.  
  171.     return
  172.  
  173. loadLogEntry: procedure expose log.
  174.     if arg() ~= 2 then do
  175.         rc = "loadLogEntry: bad args"
  176.         signal error
  177.     end
  178.     parse arg mailbox, handle
  179.  
  180.         drop log.
  181.         log. = ''
  182.  
  183.     if ~exists(mailboxDir(mailbox)) then do
  184.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  185.         return
  186.     end
  187.  
  188.     opened = open(handle, logFile(mailbox, handle), 'r')
  189.         if opened then do
  190.         call showDebugger('Loading entry' logFile(mailbox, handle))
  191.         do while ~eof(handle)
  192.             line = readln(handle)
  193.             parse upper var line variable '=' value
  194.             log.variable = value
  195.         end
  196.         call close(handle)
  197.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  198.     return
  199.  
  200. /* pass a handle here */
  201. saveLogEntry: procedure expose log.
  202.     if arg() ~= 2 then do
  203.         rc = "saveLogEntry: bad args"
  204.         signal error
  205.     end
  206.     parse arg mailbox, handle
  207.  
  208.     if ~exists(mailboxDir(mailbox)) then do
  209.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  210.         return
  211.     end
  212.  
  213.     opened = open(handle, logFile(mailbox, handle), 'w')
  214.  
  215.     if opened then do
  216.         call showDebugger('Saving entry' logFile(mailbox, handle))
  217.         call writeln(handle, 'TYPE=' || log.type)
  218.         call writeln(handle, 'TIME=' || log.time)
  219.         call writeln(handle, 'LENGTH=' || log.length)
  220.  
  221.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  222.  
  223.         call writeln(handle, 'CIDNAME=' || log.cidname)
  224.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  225.  
  226.         call writeln(handle, 'COMMENT=' || log.comment)
  227.  
  228.         call writeln(handle, 'FILENAME=' || log.filename)
  229.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  230.  
  231.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  232.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  233.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  234.  
  235.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  236.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  237.  
  238.         call close(handle)
  239.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  240.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  241.  
  242.     return
  243.  
  244. /* pass a handle here */
  245. updateLogEntry: procedure expose log.
  246.     if arg() ~= 2 then do
  247.         rc = "updateLogEntry: bad args"
  248.         signal error
  249.     end
  250.     parse arg mailbox, handle
  251.  
  252.     if ~exists(mailboxDir(mailbox)) then do
  253.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  254.         return
  255.     end
  256.  
  257.     if ~exists(logFile(mailbox, handle)) then do
  258.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  259.         return
  260.     end
  261.     opened = open(handle, logFile(mailbox, handle), 'w')
  262.  
  263.     if opened then do
  264.         call showDebugger('Updating entry' logFile(mailbox, handle))
  265.         call writeln(handle, 'TYPE=' || log.type)
  266.         call writeln(handle, 'TIME=' || log.time)
  267.         call writeln(handle, 'LENGTH=' || log.length)
  268.  
  269.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  270.  
  271.         call writeln(handle, 'CIDNAME=' || log.cidname)
  272.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  273.  
  274.         call writeln(handle, 'COMMENT=' || log.comment)
  275.  
  276.         call writeln(handle, 'FILENAME=' || log.filename)
  277.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  278.  
  279.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  280.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  281.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  282.  
  283.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  284.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  285.  
  286.         call close(handle)
  287.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  288.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  289.  
  290.     return
  291.  
  292.  
  293.  
  294. showDebugger: procedure
  295.     if arg() ~= 1 then do
  296.         say "showDebugger: ERROR"
  297.         exit 20
  298.     end
  299.  
  300.     parse arg debuggerInfo
  301.     
  302.     firstLine = sourceline(1)
  303.     parse var firstLine '/*' 'TITLE:' title '*/'
  304.     if showlist('p', 'AVMLOGGER') then
  305.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  306.     else
  307.         say title ':' debuggerInfo
  308.  
  309.     return 
  310.  
  311. /*-----------------------------------------------------------------------*/
  312. /*                         signal processing                             */
  313.  
  314. arexxerror:
  315. error:
  316.     call showDebugger("Error" rc "at line" sigl)
  317.     exit 20
  318.  
  319. break_c:
  320. halt:
  321.     call showDebugger("Halt/Break_C at line" sigl)
  322.     exit 20
  323.  
  324. novalue:
  325.     call showDebugger("No value at line" sigl)
  326.     exit 20
  327.  
  328. syntax:
  329.     call showDebugger("Syntax error" rc "at line" sigl)
  330.     exit 20
  331.  
  332. exit
  333.  
  334. /* this requires logfunctions.avm */
  335.  
  336. loadMailbox: procedure expose mailbox.
  337.     if arg() ~= 1 then do
  338.         rc = "loadMailbox: bad args"
  339.         signal error
  340.     end
  341.  
  342.         mailbox. = ''
  343.     parse arg mailbox
  344.  
  345.     handle = 'mailboxconfig'
  346.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  347.     if opened then do
  348.         do while ~eof(handle)
  349.             line = readln(handle)
  350.             parse upper var line variable '=' value
  351.             mailbox.variable = value
  352.         end
  353.         call close(handle)
  354.     end
  355.     return
  356.  
  357. /* pass a handle here */
  358. saveMailbox: procedure expose mailbox.
  359.     if arg() ~= 1 then do
  360.         rc = "saveMailbox: bad args"
  361.         signal error
  362.     end
  363.     parse arg mailbox
  364.  
  365.     handle = 'mailboxconfig'
  366.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  367.  
  368.     if opened then do
  369.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  370.  
  371.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  372.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  373.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  374.  
  375.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  376.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  377.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  378.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  379.  
  380.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  381.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  382.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  383.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  384.  
  385.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  386.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  387.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  388.  
  389.         call close(handle)
  390.     end
  391.  
  392.     return
  393.  
  394. stdabort:
  395. exit
  396.  
  397. stdbusy:
  398. exit
  399.  
  400. stderror:
  401. exit
  402.  
  403. stdtimedout:
  404. exit
  405.  
  406. stdfaxinstruct:
  407. 'playvoice' 'avm:voices/FaxStarting'
  408. action = rc
  409. select
  410.   when action = 0 then nop
  411.   when action = 1 then do; call checkifabort; end
  412.   when action = 4 then nop
  413.   when action = 5 then nop
  414.   when action = 8 then signal stdbusy
  415.   when action = 12 then signal stdabort
  416.   when action = 14 then nop
  417.   when action = 16 then nop
  418.   otherwise signal arexxerror
  419. end
  420.  
  421. stdfax:
  422. faxscript = getclip(address() || 'FAXSCRIPT')
  423. if faxscript = '' then faxscript = 'handlefax'
  424. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  425. else address rexx faxscript address() 'anonymous'
  426. exit
  427.  
  428. stddatainstruct:
  429. 'playvoice' 'avm:voices/DataStarting'
  430. action = rc
  431. select
  432.   when action = 0 then nop
  433.   when action = 1 then do; call checkifabort; end
  434.   when action = 4 then nop
  435.   when action = 5 then nop
  436.   when action = 8 then signal stdbusy
  437.   when action = 12 then signal stdabort
  438.   when action = 14 then nop
  439.   when action = 16 then nop
  440.   otherwise signal arexxerror
  441. end
  442.  
  443. stddata:
  444. datascript = getclip(address() || 'DATASCRIPT')
  445. if datascript = '' then datascript = 'handledata'
  446. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  447. else address rexx datascript address()
  448. exit
  449.  
  450. checkifabort:
  451. 'readnkeys' '1' '3'
  452. action = rc
  453. if action = 0 then value = result
  454. select
  455.   when action = 0 then do; if value = '*' then signal stdabort; end
  456.   when action = 4 then nop
  457.   when action = 5 then nop
  458.   when action = 8 then signal stdbusy
  459.   when action = 10 then nop
  460.   when action = 12 then signal stdabort
  461.   when action = 14 then signal stderror
  462.   when action = 16 then signal stderror
  463.   otherwise signal arexxerror
  464. end
  465. return
  466.  
  467.  
  468.